import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:top_foundation/component/dialog_util.dart';
import 'package:whale/helper/component/component.dart';
import 'package:whale/helper/utils/util.dart';

import '../model/problem_list.dart';

void showTagsDialog(List<ProblemList> list) {
  Get.bottomSheet(
    Container(
      color: Colors.white,
      padding: EdgeInsets.only(top: 10.r),
      child: ListView.builder(
          padding: EdgeInsets.zero,
          itemBuilder: (_, idx) {
            return TagsDialogCell(
              md: list[idx],
              idx: idx,
            );
          },
          itemCount: list.length),
    ),
  );
}

void showTagAlert(ProblemList md, {String? iden}) {
  showDialog(
      context: Get.context!,
      builder: (_) {
        return Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              constraints: BoxConstraints(maxHeight: 0.7.sh),
              margin: EdgeInsets.symmetric(horizontal: 20.r),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(10),
              ),
              child: Stack(
                children: [
                  ClipRRect(
                    borderRadius: BorderRadius.circular(10),
                    child: SingleChildScrollView(
                      physics: const ClampingScrollPhysics(),
                      child: TagsDialogCell(
                        md: md,
                        idx: 1,
                        iden: iden,
                      ),
                    ),
                  ),
                  Positioned(
                    right: 0,
                    child: InkWell(
                      onTap: () {
                        Get.back();
                      },
                      child: Icon(
                        IconUtil.circle_wrong,
                        color: ColorsUtil.content,
                        size: 20.r,
                      ),
                    ),
                  )
                ],
              ),
            ),
          ],
        );
      });
}

class TagsDialogCell extends StatelessWidget {
  const TagsDialogCell({
    Key? key,
    required this.md,
    required this.idx,
    this.iden,
  }) : super(key: key);
  final ProblemList md;
  final int idx;
  final String? iden;
  @override
  Widget build(BuildContext context) {
    return Container(
      color: ColorsUtil.bg,
      padding: EdgeInsets.only(bottom: 10.r),
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 20.r, vertical: 10.r),
        decoration: BoxDecoration(
          color: idx % 2 == 0 ? Colors.white : ColorsUtil.bg,
          boxShadow: idx % 2 == 0
              ? [
                  BoxShadow(
                    color: Colors.grey.withAlpha(40),
                    offset: const Offset(2, 1),
                  ),
                  BoxShadow(
                    color: Colors.grey.withAlpha(30),
                    offset: const Offset(2, 3),
                  ),
                  BoxShadow(
                    color: Colors.grey.withAlpha(20),
                    offset: const Offset(2, 5),
                  ),
                  BoxShadow(
                    color: Colors.grey.withAlpha(10),
                    offset: const Offset(2, 7),
                  ),
                ]
              : [],
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Container(
                  decoration: BoxDecoration(
                    color: ColorsUtil.theme,
                    borderRadius: BorderRadius.circular(2),
                  ),
                  padding:
                      const EdgeInsets.symmetric(vertical: 2, horizontal: 5),
                  margin: EdgeInsets.only(right: 5.r),
                  child: Text(
                    iden ?? (idx + 1).toString(),
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 9.sp,
                    ),
                  ),
                ),
                Text(
                  '批注原文：',
                  style: TextStyle(
                    color: ColorsUtil.title,
                    fontSize: 12.sp,
                    fontWeight: FontWeight.bold,
                  ),
                )
              ],
            ),
            SizedBox(
              height: 10.r,
            ),
            Text(
              md.problemContent ?? '',
              style: TextStyle(
                color: ColorsUtil.content,
                fontSize: 12.sp,
              ),
            ),
            Container(
              margin: EdgeInsets.symmetric(vertical: 10.r),
              child: const DashLine(
                width: 1,
                space: 1,
                color: Color(0xffCFD4DE),
              ),
            ),
            Column(
              children: md.problemRuleList
                      ?.map(
                        (e) => Column(
                          children: [
                            Text(
                              '违反${e.ruleTitle ?? ''}${e.ruleContent ?? ''}',
                              style: TextStyle(
                                color: ColorsUtil.subTitle,
                                fontSize: 12.sp,
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.symmetric(vertical: 8.r),
                              child: const DashLine(
                                width: 1,
                                space: 1,
                                color: Color(0xffCFD4DE),
                              ),
                            ),
                          ],
                        ),
                      )
                      .toList() ??
                  [],
            ),
            Column(
              children: md.problemCaseList
                      ?.map(
                        (e) => Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                              alignment: Alignment.center,
                              width: 49.r,
                              height: 15.r,
                              margin: EdgeInsets.only(bottom: 12.r),
                              decoration: BoxDecoration(
                                  color: const Color(0xff9FB9EC),
                                  borderRadius: BorderRadius.circular(2)),
                              child: Text(
                                '参考案例',
                                style: TextStyle(
                                  fontSize: 10.sp,
                                  color: Colors.white,
                                ),
                              ),
                            ),
                            Text(
                              e.caseName ?? '',
                              style: TextStyle(
                                color: ColorsUtil.theme,
                                fontSize: 12.sp,
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.symmetric(vertical: 8.r),
                              child: const DashLine(
                                width: 1,
                                space: 1,
                                color: Color(0xffCFD4DE),
                              ),
                            ),
                            Text(
                              '${iden == null ? '' : '案例简介：'}${e.caseIntroduction ?? ''}',
                              style: TextStyle(
                                color: ColorsUtil.subTitle,
                                fontSize: 12.sp,
                              ),
                            ),
                          ],
                        ),
                      )
                      .toList() ??
                  [],
            )
          ],
        ),
      ),
    );
  }
}
